package algotithm.acwing.rangeofproblems.test908;

import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/30-22:12
 * @Title 908. 最大不相交区间数量
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(String.valueOf(reader.readLine()));

        ArrayList<int[]> list = new ArrayList<>();
        while(n-- > 0) {
            String[] num = reader.readLine().split(" ");
            int[] arr = new int[2];
            arr[0] = Integer.parseInt(num[0]);
            arr[1] = Integer.parseInt(num[1]);
            list.add(arr);
        }
        list.sort(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1] - o2[1];
            }
        });

        int res = 0;
        int end = Integer.MIN_VALUE;
        for (int i = 0; i < list.size(); i++) {
            int l = list.get(i)[0];
            int r = list.get(i)[1];
            if (l > end) {
                res++;
                end = r;
            }
        }
        writer.write(res + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }

}
